package com.molichuxing.services.infrastructure.convertor;

import com.molichuxing.framework.utils.CollectionUtils;
import com.molichuxing.services.infrastructure.bean.*;
import com.molichuxing.services.infrastructure.dto.response.request.create.LoginLogCreateDto;
import com.molichuxing.services.infrastructure.dto.response.request.create.OperationLogCreateDto;
import com.molichuxing.services.infrastructure.dto.response.response.*;
import com.molichuxing.services.property.GroupSystemTypeEnum;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class Convert {

    public static List<AccountDto> toAccountDtoList(List<AccountBean> beans) {
        List<AccountDto> list = null;
        if (CollectionUtils.isNotEmpty(beans)) {
            list = new ArrayList<AccountDto>();
            for (AccountBean bean : beans) {
                list.add(toAccountDto(bean));
            }
        }
        return list;
    }

    public static AccountDto toAccountDto(AccountBean bean) {
        AccountDto beanDto = null;
        if (bean != null) {
            beanDto = new AccountDto();
            BeanUtils.copyProperties(bean, beanDto);
        }

        return beanDto;
    }

    public static List<AccountDealerDto> toAccountDealerDtoList(List<AccountDealerBean> beans) {
        List<AccountDealerDto> list = null;
        if (!CollectionUtils.isEmpty(beans)) {
            list = new ArrayList<AccountDealerDto>();
            for (AccountDealerBean bean : beans) {
                list.add(toAccountDealerDto(bean));
            }
        }
        return list;
    }

    public static AccountDealerDto toAccountDealerDto(AccountDealerBean bean) {
        AccountDealerDto beanDto = null;
        if (bean != null) {
            beanDto = new AccountDealerDto();
            BeanUtils.copyProperties(bean, beanDto);
        }

        return beanDto;
    }

    public static List<AccountGroupDto> toAccountGroupDtoList(List<AccountGroupBean> beans) {
        List<AccountGroupDto> dataList = null;
        if (CollectionUtils.isNotEmpty(beans)) {
            dataList = new ArrayList<>();
            for (AccountGroupBean bean : beans) {
                dataList.add(toAccountGroupDto(bean));
            }
        }
        return dataList;
    }

    public static AccountGroupDto toAccountGroupDto(AccountGroupBean bean) {
        AccountGroupDto beanDto = null;
        if (bean != null) {
            beanDto = new AccountGroupDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    public static List<GroupDto> toGroupDtoList(List<GroupBean> beans) {
        List<GroupDto> dataList = null;
        if (CollectionUtils.isNotEmpty(beans)) {
            dataList = new ArrayList<>();
            for (GroupBean bean : beans) {
                dataList.add(toGroupDto(bean));
            }
        }
        return dataList;
    }

    public static GroupDto toGroupDto(GroupBean bean) {
        GroupDto beanDto = null;
        if (bean != null) {
            beanDto = new GroupDto();
            BeanUtils.copyProperties(bean, beanDto);
            if (bean.getGroupSystemType() != null) {
                beanDto.setGroupSystemType(GroupSystemTypeEnum.getEnum(bean.getGroupSystemType()));
            }
        }
        return beanDto;
    }

    public static List<AccountGroupBean> toAccountGroupBeanList(List<AccountGroupDto> dtoList) {
        List<AccountGroupBean> result = null;
        if (CollectionUtils.isNotEmpty(dtoList)) {
            result = new ArrayList<>();
            for (AccountGroupDto dto : dtoList) {
                result.add(toAccountGroupBean(dto));
            }
        }
        return result;
    }

    public static AccountGroupBean toAccountGroupBean(AccountGroupDto dto) {
        AccountGroupBean bean = null;
        if (dto != null) {
            bean = new AccountGroupBean();
            BeanUtils.copyProperties(dto, bean);
        }
        return bean;
    }

    public static OperationLogBean toOperationLogBean(OperationLogCreateDto bean) {
        OperationLogBean beanDto = null;
        if (bean != null) {
            beanDto = new OperationLogBean();
            BeanUtils.copyProperties(bean, beanDto);
        }

        return beanDto;
    }

    public static List<OperationLogDto> toOperationLogDto(List<OperationLogBean> beanList) {
        List<OperationLogDto> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (OperationLogBean bean : beanList) {
                dtoList.add(toOperationLogDto(bean));
            }
        }

        return dtoList;
    }

    public static OperationLogDto toOperationLogDto(OperationLogBean bean) {
        OperationLogDto beanDto = null;
        if (bean != null) {
            beanDto = new OperationLogDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    public static List<LoginLogDto> toLoginLogBeanDto(List<LoginLogBean> beanList) {
        List<LoginLogDto> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (LoginLogBean bean : beanList) {
                dtoList.add(toLoginLogBeanDto(bean));
            }
        }

        return dtoList;
    }

    public static LoginLogDto toLoginLogBeanDto(LoginLogBean bean) {
        LoginLogDto beanDto = null;
        if (bean != null) {
            beanDto = new LoginLogDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    public static AccountBean toAccountBean(AccountDto dto) {
        AccountBean bean = null;
        if (dto != null) {
            bean = new AccountBean();
            BeanUtils.copyProperties(dto, bean);
            bean.setSystemType(dto.getSystemType() != null ? dto.getSystemType().getValue() : null);
        }
        return bean;
    }

    public static AccountDealerBean toAccountDealerBean(AccountDealerDto dto) {
        AccountDealerBean bean = null;
        if (dto != null) {
            bean = new AccountDealerBean();
            BeanUtils.copyProperties(dto, bean);
        }
        return bean;
    }

    public static GroupBean toGroupBean(GroupDto dto) {
        GroupBean bean = null;
        if (dto != null) {
            bean = new GroupBean();
            BeanUtils.copyProperties(dto, bean);
            bean.setGroupSystemType(dto.getGroupSystemType() != null ? dto.getGroupSystemType().getValue() : null);
        }
        return bean;
    }

    public static List<GroupResourceDto> toGroupResourceDtoList(List<GroupResourceBean> beans) {
        List<GroupResourceDto> dtos = null;
        if (CollectionUtils.isNotEmpty(beans)) {
            dtos = new ArrayList<>();
            for (GroupResourceBean bean : beans) {
                dtos.add(toGroupResourceDto(bean));
            }
        }
        return dtos;
    }

    public static GroupResourceDto toGroupResourceDto(GroupResourceBean bean) {
        GroupResourceDto dto = null;
        if (bean != null) {
            dto = new GroupResourceDto();
            BeanUtils.copyProperties(bean, dto);
        }
        return dto;
    }

    public static List<ResourceDto> toResourceDtoList(List<ResourceBean> beans) {
        List<ResourceDto> dtos = null;
        if (CollectionUtils.isNotEmpty(beans)) {
            dtos = new ArrayList<>();
            for (ResourceBean bean : beans) {
                dtos.add(toGroupResourceDto(bean));
            }
        }
        return dtos;
    }

    public static ResourceDto toGroupResourceDto(ResourceBean bean) {
        ResourceDto dto = null;
        if (bean != null) {
            dto = new ResourceDto();
            BeanUtils.copyProperties(bean, dto);
        }
        return dto;
    }

    public static List<GroupDesenseDto> toGroupDesenseDtoList(List<GroupDesenseBean> beans) {
        List<GroupDesenseDto> dtos = null;
        if (CollectionUtils.isNotEmpty(beans)) {
            dtos = new ArrayList<>();
            for (GroupDesenseBean bean : beans) {
                dtos.add(toGroupDesenseDto(bean));
            }
        }
        return dtos;
    }

    public static GroupDesenseDto toGroupDesenseDto(GroupDesenseBean bean) {
        GroupDesenseDto dto = null;
        if (bean != null) {
            dto = new GroupDesenseDto();
            BeanUtils.copyProperties(bean, dto);
        }
        return dto;
    }

    public static List<DesenseDto> toDesenseDtoList(List<DesenseBean> beans) {
        List<DesenseDto> dtos = null;
        if (CollectionUtils.isNotEmpty(beans)) {
            dtos = new ArrayList<>();
            for (DesenseBean bean : beans) {
                dtos.add(toDesenseDto(bean));
            }
        }
        return dtos;
    }

    public static DesenseDto toDesenseDto(DesenseBean bean) {
        DesenseDto dto = null;
        if (bean != null) {
            dto = new DesenseDto();
            BeanUtils.copyProperties(bean, dto);
        }
        return dto;
    }

    public static AccountBean toAccountBean(AccountCreateDto dto) {
        AccountBean bean = null;
        if (dto != null) {
            bean = new AccountBean();
            BeanUtils.copyProperties(dto, bean);
        }
        return bean;
    }

    public static AccountBean toAccountBean(AccountModifyDto dto) {
        AccountBean bean = null;
        if (dto != null) {
            bean = new AccountBean();
            BeanUtils.copyProperties(dto, bean);
        }
        return bean;
    }

    public static GroupBean toGroupBean(GroupCreateDto dto) {
        GroupBean bean = null;
        if (dto != null) {
            bean = new GroupBean();
            BeanUtils.copyProperties(dto, bean);
        }
        return bean;
    }

    public static GroupBean toGroupBean(GroupModifyDto dto) {
        GroupBean bean = null;
        if (dto != null) {
            bean = new GroupBean();
            BeanUtils.copyProperties(dto, bean);
        }
        return bean;
    }

    public static LoginLogBean toLoginLogBean(LoginLogDto dto) {
        LoginLogBean bean = null;
        if (dto != null) {
            bean = new LoginLogBean();
            BeanUtils.copyProperties(dto, bean);
        }
        return bean;
    }

    public static LoginLogBean toLoginLogBean(LoginLogCreateDto createDto) {
        LoginLogBean bean = null;
        if (createDto != null) {
            bean = new LoginLogBean();
            BeanUtils.copyProperties(createDto, bean);
            bean.setType(createDto.getType().getValue());
        }
        return bean;
    }

    public static List<SensitiveWordDto> toSensitiveWordDtoList(List<SensitiveWordBean> beans) {
        List<SensitiveWordDto> dtos = null;
        if (CollectionUtils.isNotEmpty(beans)) {
            dtos = new ArrayList<>();
            for (SensitiveWordBean bean : beans) {
                dtos.add(toSensitiveWordDto(bean));
            }
        }
        return dtos;
    }

    public static SensitiveWordDto toSensitiveWordDto(SensitiveWordBean beanDto) {
        SensitiveWordDto dto = null;
        if (beanDto != null) {
            dto = new SensitiveWordDto();
            BeanUtils.copyProperties(beanDto, dto);
        }

        return dto;
    }

    public static List<LoginLogDto> toLoginLogDto(List<LoginLogBean> beanList) {
        List<LoginLogDto> beanDtoList = null;
        if (beanList != null && beanList.size() > 0) {
            beanDtoList = new ArrayList<>();
            for (LoginLogBean bean : beanList) {
                beanDtoList.add(toLoginLogDto(bean));
            }
        }

        return beanDtoList;
    }

    public static LoginLogDto toLoginLogDto(LoginLogBean bean) {
        LoginLogDto beanDto = null;
        if (bean != null) {
            beanDto = new LoginLogDto();
            BeanUtils.copyProperties(bean, beanDto);
        }

        return beanDto;
    }
}